********Tables P.1 and P.2 - Indonesia********

eststo clear

*Load data and create differences
cd "$reploc/data/created_data"
use indo_full, clear

sort pidlink ifls
drop if ifls==.
keep if panel==1


keep rbuc* riskaverse gambleaverse ifls pidlink inflation imp_age panel biryear_impl grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co? birprov_impl

gen riskaverseuse=riskaverse if rbuc_garefined!=.
drop riskaverse

reshape wide rbuc* riskaverseuse gambleaverse inflation imp_age panel grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co?, i(pidlink) j(ifls)


local varlist1 rbuc rbucB rbuc_nga rbuc_garefined rbucgaref1a rbucgaref2a rbucgaref3a rbucgaref4a riskaverseuse gambleaverse inflation grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co2 grbrprovSD_lam0co2 grbrprovAvg_lam0co3 grbrprovSD_lam0co3 


foreach var in `varlist1'  {
gen `var'dif=.
replace `var'dif=`var'5-`var'4
}

*Generate cohort by birthyear variables to cluster on
egen coh_prov_clust=group(biryear_impl birprov_impl)

*Table P.1 - Regressions
local x rbuc_garefined
local rhsvari oldindoonly
local rhsvaruse _lam0co3dif
local usei grbr

drop if `x'dif==.


*Column 1
eststo:  oprobit `x'dif  `usei'provAvg`rhsvaruse'  inflationdif, vce(cluster coh_prov_clust)

*Column 2
eststo:  oprobit `x'dif `usei'provSD`rhsvaruse'  inflationdif, vce(cluster coh_prov_clust)

*Column 3
eststo:  oprobit `x'dif  `usei'provAvg`rhsvaruse' `usei'provSD`rhsvaruse'  inflationdif, vce(cluster coh_prov_clust)


cd "$reploc/results"	
esttab using TableP1_Indonesia.tex, star(* 0.1 ** 0.05 *** 0.01) b(2) se(2) replace

*Table P.2 - Regressions

eststo clear

local x riskaverseuse
local rhsvari oldindoonly
local rhsvaruse _lam0co3dif
local usei grbr

drop if `x'dif==.


*Column 1
eststo:  reg `x'dif  `usei'provAvg`rhsvaruse'  inflationdif, vce(cluster coh_prov_clust)

*Column 2
eststo:  reg `x'dif `usei'provSD`rhsvaruse'  inflationdif, vce(cluster coh_prov_clust)

*Column 3
eststo:  reg `x'dif  `usei'provAvg`rhsvaruse' `usei'provSD`rhsvaruse'  inflationdif, vce(cluster coh_prov_clust)


cd "$reploc/results"	
esttab using TableP2_Indonesia.tex, star(* 0.1 ** 0.05 *** 0.01) b(2) se(2) replace
